refactor(mercury): remove unnecessary array allocation and copy in decode_pack_object#755
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@el-ev Hello, the A good analogy would be placing a group of pufferfish into a fixed-volume container. When the pufferfish inflate, the container's lid inevitably pops open due to the increased volume. Similarly, when For this reason, we must accurately estimate the final memory consumption of So,
The memory of let r: Result<CacheObject, GitError> = self.decode_pack_object(&mut reader, &mut offset);
match r {
Ok(mut obj) => {
obj.set_mem_recorder(self.cache_objs_mem.clone());
obj.record_mem_size();My goal is to ensure that this transformation does not disrupt memory control. Since we cannot just kick out objects before they reach the Imagine a small, isolated island trying to manage its population knowing that new members will inevitably be born. Without careful planning and foresight, overcrowding would be unavoidable.
The |
|
@MrBeanCpp I understand your consideration now, and I will push some fix for the issue (ideally not simply revert the commit). However, I can't agree that pre-creating a much larger vector and do heavy coipes is the proper way to limit the memory usage. It is worth noting that fn heap_size(&self) {
if &self.is_delta() {
self.data_decompress.heap_size() + self.expanded_size
} else {
self.data_decompress.heap_size()
}
}I think it could satisty your requirement, without huge runtime overhead. |
|
Sounds good, you can monitor the memory usage during the decoding process to evaluate the effectiveness of memory control. |
The lambda function does not work as it is described. And it introduces unnecessary memory and time overhead.
It says that it keeps track of the new Object indexed by the Delta object. But that new Object will be created by
Pack::rebuild_delta(), and well recorded inprocess_delta():The memory used by the Delta object, which is said to be the size of the new Object, is released after
Pack::rebuild_delta()returns.During the whole lifetime of the Delta object, the new Object does not even exist in the memory, so it's meaningless to keep track of it. Instead, the memory used by the Delta object itself should be recorded.